// SMSDispatch.cpp: implementation of the CSMSDispatch class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "log4cplus_switch.h"
#include <string>
#include <list>
#include <map>
#include "SMSItem.h"
#include "SMSDispatch.h"
#include  "SMSQueue.h"
#include <common/Pool.h>
#include "NETLIB\TCPClient.h"
#include "Account.h"
#include "AccountManager.h"
#include "IF.h"
#include "IFManager.h"
#include "netlib/SocketEngine.h"
#include "SMSApp.h"
#include "SMSDispatch.h"


LOG4CPLUS_CLASS_IMPLEMENT( CSMSDispatch, _s_logger, "CSMSDispatch" );

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSMSDispatch::CSMSDispatch()
{

}

CSMSDispatch::~CSMSDispatch()
{

}

void CSMSDispatch::PeriodDispatch()
{
	CSMSApp* pApp = CSMSApp::GetInstance();
	std::list<CSMSItem*>::iterator it;
	for(it=pApp->m_SMSList.begin(); it!=pApp->m_SMSList.end();)
	{
		CSMSItem* pSMS = *it;
		//dispatch the sms to the dest account by orgaddr and destaddr
		//dispatch the succeeed response to the billing addr or somewhere eles
		//may some wise solution here, such as this account can't deal sms now, can 
		//transfer some sms to other account
		pApp->m_AccountManager.SubmitSMS(pSMS);
		it=pApp->m_SMSList.erase(it);
		
	}
	//begin dispatch every account SMSQueue now

}
